package com.dotflat.staffExtend.repository;

import com.dotflat.staffExtend.domain.StaffExtendCareer;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface StaffExtendCareerRepository extends JpaRepository<StaffExtendCareer, String>, JpaSpecificationExecutor<StaffExtendCareer> {

    @Modifying
    @Transactional
    void deleteAllByExtendInfoId(String extendInfoId);

    @Query(value="select `id`, `created`, `deleted`, `areaId`, `audited`, `createdBy`, `beginDate`, `description`, `endDate`, `staffId`, `extendInfoId`, `reserved`" +
            " from ex_staff_extend_career where areaId = :areaId and reserved = :reserved and endDate is null  LIMIT 1 ",nativeQuery = true)
    StaffExtendCareer findByAreaIdAndReserved(@Param("areaId")String areaId, @Param("reserved")String reserved);

}
